// Declaration de variables externes.
uniform extern float4x4 gWVP;
uniform extern float gTime;

static float amplitude[2] = {10.0f, 1.0f};
static float waveNum[2] =	{1.0f, 8.0f};
static float frequence[2] = {1.0f, 8.0f};
static float phase[2] =		{0.0f, 1.0f};

// Concordance de la structure de vertex CPU-GPU
struct OutputVS
{
	float4 posH : POSITION0;
	float4 color : COLOR0;
};

float SumOfRadialSineWaves(float x, float z)
{
	// Distance du point milieu
	float dist = sqrt(x*x + z*z);

	// sum des vagues
	float sum = 0.0f;

	// Additionne toute les vagues entre elles.
	for(int i = 0; i < 2; ++i)
	{
		sum += amplitude[i]*sin(waveNum[i]*dist - gTime*frequence[i] + phase[i]);	
	}

	return sum;
}

// Fonction Vertex Shader
OutputVS TransformVS(float3 posL : POSITION0, float4 color: COLOR0)
{
	OutputVS outVS = (OutputVS)0;

	posL.y = SumOfRadialSineWaves(posL.x, posL.z);

	outVS.posH = mul(float4(posL, 1.0f), gWVP);
	outVS.color = color;

	return outVS;
}

float4 TransformPS(float4 color: COLOR0) : COLOR
{
	return color;
}

technique TransformTech
{
	pass P0
	{
		vertexShader = compile vs_2_0 TransformVS();
		pixelShader = compile ps_2_0 TransformPS();

		FillMode = WireFrame;
	}
}